using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using InverseClockWork.Extra.Cutscenes.Actions;
using System.Linq;
using UnityEditor.AddressableAssets.Settings;

namespace InverseClockWork.Extra.Cutscenes
{
    [CustomEditor(typeof(ActionAddrDialogBox))]
    public class ActionAddrDialogBoxEditor : Editor
    {
        private static AddressableAssetEntry EntryCache
        {
            get; set;
        } = null;

        public override void OnInspectorGUI()
        {
            //base.OnInspectorGUI();

            string addrAddress = typeof(ActionAddrDialogBox).GetField("config_addressableAddress", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(target) as string;
            if (EntryCache == null)
            {
                if (addrAddress != null && addrAddress.Length > 0)
                {
                    //Do check

                    var settings = UnityEditor.AddressableAssets.AddressableAssetSettingsDefaultObject.Settings;
                    if (settings && settings.DefaultGroup != null)
                    {
                        EntryCache = settings.DefaultGroup.entries.Where(item => item.address == addrAddress).FirstOrDefault();
                    }
                }
            }
            if (EntryCache == null)
            {
                GUILayout.Label("Addressable is not set. Use path:");
                GUILayout.TextField(addrAddress);
            }
            /*else
            {
                base.OnInspectorGUI();
            }*/
        }
    }
}